import Router from 'vue-router'

function init(Vue) {
  Vue.use(Router)
  return new Router({
    mode: 'history',
    base: `${process.env.VUE_APP_ROUTER_BASE}`,
    routes: [
      {
        path: '/',
        name: 'home',
        redirect: 'dashboard'
      },
      {
        path: '/dashboard',
        name: 'dashboard',
        component: () =>
          import(/* webpackChunkName: "dashboard" */ './views/home.vue'),
        meta: {
          pageName: false
        }
      },
      {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
          import(/* webpackChunkName: "about" */ './views/about.vue'),
        meta: {
          // 以下几个配置将继承到子路由，若子路由需要做反向处理，则需要单独配置，
          // 如子路由的meta.pageName设置为true，可参考路由最后的/base/:id配置
          // 是否显示头部
          // header: false,
          // 是否显示页面名称
          pageName: false,
          // 是否保留页面留白
          pageBlank: false,
          // 是否显示内容区背景图(大banner)
          contentBg: false
        }
      },
      {
        path: '/form',
        name: 'form',
        component: () =>
          import(/* webpackChunkName: "form" */ './views/form/form.vue')
      },
      {
        path: '/table-list',
        name: 'table-list',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
          import(
            /* webpackChunkName: "table-list" */ './views/table/table-list.vue'
          )
      },
      {
        path: '/base/:id',
        name: 'base',
        component: () =>
          import(/* webpackChunkName: "base" */ './views/base.vue'),
        meta: {
          // 是否显示头部
          header: false
        },
        children: [
          {
            path: ':subId',
            name: 'base/sub-3',
            component: () =>
              import(/* webpackChunkName: "base" */ './views/base-sub.vue'),
            meta: {
              // 由于父路由设置为false，但子路由又希望是显示这个头部的
              header: true
            }
          }
        ]
      }
    ]
  })
}

export default {
  init
}
